<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>06函数</title>
</head>
<body>
<script>
    //1.JS通过function关键字来定义函数
    function f1(){
        console.log('你好!星期五!');
    }
    f1();//调用函数
    f1();
    f1();

    function f2(n){
        console.log('形参值:'+n);
    }
    f2(666);
    f2('下午好');

    function f3(a,b){
        console.log(a);
        console.log(b);
        console.log(a+b);
    }
    f3(2,3);//5
    //形参个数大于实参个数,未被赋值的形参值为undefined
    f3(2);//NAN(Not a Number)
    //形参个数小于实参个数,多余的实参值会被舍弃掉
    f3(3,4,5);//7

    //arguments用来保存调用函数传入的实参,可以看到实参的个数和值
    function f4(){
        console.log(arguments);
    }
    f4(50);//Arguments [50, callee: ƒ, Symbol(Symbol.iterator): ƒ]
    f4(50,60);//Arguments(2) [50, 60, callee: ƒ, Symbol(Symbol.iterator): ƒ]
    f4(50,60,70);//Arguments(3) [50, 60, 70, callee: ƒ, Symbol(Symbol.iterator): ƒ]

    function f5(x,y){
        return x+y;
    }
    console.log(f5(2,3));
    //调用f5的方法传参并赋值给res
    let res = f5(10,10);
    console.log(res);

    //第二种函数声明方式
    let f6 = function (){
        console.log('第二种');
    }
    f6();
    console.log(f6);
    console.log(typeof f6);

    //第三种函数声明方式
    let f7 = new Function("name","age","console.log('方法体');return age;");
    console.log(f7('小明',18));

</script>
</body>
</html>